package com.onenine.app.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onenine.app.R;
import com.onenine.app.model.RechargeItem;
import com.onenine.app.utils.RoleResLoader;
import com.onenine.common.util.ApUtils;

import java.util.List;

public class RechargeAdapter extends BaseQuickAdapter<RechargeItem, BaseViewHolder> {

    private boolean autoItemSelected;

    public RechargeAdapter(@Nullable List<RechargeItem> data) {
        super(R.layout.layout_recharge_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RechargeItem item) {
        helper.setText(R.id.tv_diamond_amount, ApUtils.getApp()
                .getString(R.string.format_diamond_num, item.getDiamondNum() + ""))
                .setText(R.id.tv_diamond_value, item.getRechargeMoney())
                .setVisible(R.id.iv_recommend, item.isRecommend());
        if (!autoItemSelected && helper.getAdapterPosition() == 0) {
            //自动选择第一项
            setOnItemClick(helper.getConvertView(), 0);
            autoItemSelected = true;
        }
    }

    /**
     * 设置选中状态
     *
     * @param currentView
     * @param previousView
     */
    public void setItemSelected(View currentView, View previousView) {
        if (currentView != null) {
            currentView.findViewById(R.id.rl_recharge)
                    .setBackgroundResource(RoleResLoader.getRoleDrawableResourceId(RoleResLoader.DynamicResName.IC_RECHARGE_ITEM_BORDER));
            TextView tvDiamondNum = currentView.findViewById(R.id.tv_diamond_amount);
            tvDiamondNum.setTextColor(RoleResLoader.getRoleColorResourceId(RoleResLoader.DynamicResName.THEME_COLOR));
            TextView tvRechargeMoney = currentView.findViewById(R.id.tv_diamond_value);
            tvRechargeMoney.setTextColor(RoleResLoader.getRoleColorResourceId(RoleResLoader.DynamicResName.THEME_COLOR));
            TextView tvRmb = currentView.findViewById(R.id.tv_diamond_rmb);
            tvRmb.setTextColor(RoleResLoader.getRoleColorResourceId(RoleResLoader.DynamicResName.THEME_COLOR));
        }
        if (previousView != null) {
            previousView.findViewById(R.id.rl_recharge)
                    .setBackgroundResource(R.drawable.shape_recharge_item_border_bg);
            TextView tvDiamondNum = previousView.findViewById(R.id.tv_diamond_amount);
            tvDiamondNum.setTextColor(ActivityCompat.getColor(ApUtils.getApp(), R.color.c333));
            TextView tvRechargeMoney = previousView.findViewById(R.id.tv_diamond_value);
            tvRechargeMoney.setTextColor(ActivityCompat.getColor(ApUtils.getApp(), R.color.c333));
            TextView tvRmb = previousView.findViewById(R.id.tv_diamond_rmb);
            tvRmb.setTextColor(ActivityCompat.getColor(ApUtils.getApp(), R.color.c333));
        }
    }

}
